package net.wicp.tams.plugin.task.kubernetes;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import net.wicp.tams.common.Result;
import net.wicp.tams.common.others.kubernetes.KubeClient;
import net.wicp.tams.plugin.TaskAssit;

@Mojo(name = "addnamespace", requiresProject = false, threadSafe = true)
public class AddNamespace extends AbstractMojo {
	/***
	 * namespace名字
	 */
	@Parameter(property = "name", required = true)
	private String name;
	/**
	 * apiserver的url
	 */
	@Parameter(property = "url", required = false)
	private String url;

	@Override
	public void execute() throws MojoExecutionException, MojoFailureException {
		TaskAssit.initMasterUrl(url);
		Result ret = KubeClient.createNamespace(name);
		if (ret.isSuc()) {
			getLog().info("------------------------添加命名空间成功：" + name + "---end---------");
		} else {
			throw new MojoFailureException("------------------------添加命名空间失败：" + name + "-,"+ret.getMessage()+"--end---------");
		}
	}

}
